package com.arelikebrothers.demo.concurrent.algo.pc;

import java.util.concurrent.*;

/**
 * Created by lennon on 04/05/2017.
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<PCData> queue = new ArrayBlockingQueue<>(1000);
//        BlockingQueue<PCData> queue = new LinkedBlockingDeque<>(1000);
        Producer producer1 = new Producer(queue);
        Producer producer2 = new Producer(queue);
        Producer producer3 = new Producer(queue);

        Consumer consumer1 = new Consumer(queue);
        Consumer consumer2 = new Consumer(queue);
        Consumer consumer3 = new Consumer(queue);

        ExecutorService service = Executors.newFixedThreadPool(6, (call)->{
            Thread thread = new Thread(call, "thread");
            thread.setDaemon(true);
            return thread;
        });
        service.execute(producer1);
        service.execute(producer2);
        service.execute(producer3);
        service.execute(consumer1);
        service.execute(consumer2);
        service.execute(consumer3);

        Thread.sleep(10 * 1000);
        producer1.stop();
        producer2.stop();
        producer3.stop();
        service.shutdown();
    }
}
